package com.example.testcamara;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

public class TakePicFragment extends Fragment {
    private ImageButton btn_pic;
    private CameraController mCameraControler;
    public static String BASE_PATH;// = Environment.getDataDirectory().getPath() + "/AAA";
    private VideoRecordTextureView mTextureView;
    private String TAG = "TakePicFragment";
    private String mFileName;

    @Override
    public View onCreateView (@NonNull LayoutInflater inflater, @NonNull
            ViewGroup container, @NonNull Bundle saveInstanceState) {
        View view = inflater.inflate(R.layout.fragment_take_pic, container, false);
        InitView(view);
        return view;
    }

    private void InitView(View view) {
        mTextureView = (VideoRecordTextureView) view.findViewById(R.id.tv_pic);
        mCameraControler = new CameraController(getActivity());
        BASE_PATH = getActivity().getExternalCacheDir().getPath();
        mCameraControler.setFolderPath(BASE_PATH);
        mCameraControler.setFileName(mFileName);

        btn_pic = view.findViewById(R.id.btn_pic);
        btn_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                mCameraControler.takePicture();
            }
        });
        assert mTextureView != null;
        mCameraControler.initCamera(mTextureView);
    }

    public void setFileName(String fileName) {
        mFileName = fileName;
    }

}